#pragma once

#include "Singleton.h"

class Account
{
private:
	uint64 m_id;
	std::string m_username;
	std::string m_password;
	Crypt::BigNumber m_hash;
public:
	Account(const Crypt::BigNumber bigNum, const std::string username, const std::string password, uint64 id)
		: m_id(id), m_password(password), m_username(username), m_hash(bigNum)
	{
	}

	Account() { }

	std::string GetUsername() { return m_username; }
	std::string GetPassword() { return m_password; }
	uint64 GetID() { return m_id; }
	const Crypt::BigNumber& GetHash() const { return m_hash; }
};

class AccountMgr : public Singleton<AccountMgr>
{
private:
	Database::IDatabase* m_pAccountDB;
	std::map<uint64, Account> m_Accounts;
	Concurrency::critical_section mLock;
public:
	AccountMgr(Database::IDatabase* pAccountDB);
	~AccountMgr(void);

	void Update();
	
	bool getAccount(const std::string& name, Account& acc);
	Account getAccount(uint64 id) {
		mLock.lock();
		auto ret = m_Accounts[id];
		mLock.unlock();
		return ret;
	}
};

#define sAccountMgr (AccountMgr::getInstance())

